#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution
{
public:
    vector<string> ret;
    string path;
    vector<string> letterCasePermutation(string s)
    {
        dfs(s, 0);
        return ret;
    }

    void dfs(string& s, int pos)
    {
        if (pos == s.size())
        {
            ret.push_back(path);
            return;
        }

        path += s[pos];
        dfs(s, pos + 1);
        path.pop_back();

        if (s[pos] < '0' || s[pos] > '9')
        {
            char tmp = change(s[pos]);
            path += s[pos];
            dfs(s, pos + 1);
            path.pop_back();
        }
    }

    char change(char& c)
    {
        if (c >= 'a' && c <= 'z')
            return c -= 32;
        else
            return c += 32;
    }
};

int main()
{
    string ss = "a1b2";
    Solution s;
    auto ret = s.letterCasePermutation(ss);
    for (auto& s : ret)
        cout << s << endl;
    return 0;
}